/**
 * Copyright (C) 2021-2022 maminjie <canpool@163.com>
 * SPDX-License-Identifier: LGPL-2.1
 * Powered by Qt-Advanced-Docking-System
**/

#pragma once

#include "qads_global.h"

#include <QWidget>

QT_BEGIN_NAMESPACE
class QAbstractButton;
QT_END_NAMESPACE

QADS_BEGIN_NAMESPACE

class DockTabBar;
class DockPannel;
class DockTitleBarPrivate;

/**
 * Title bar of a dock pannel.
 * The title bar contains a tabbar with all tabs for a dock widget group and
 * with a tabs menu button, a undock button and a close button.
 */
class QADS_EXPORT DockTitleBar : public QWidget
{
    Q_OBJECT
public:
    DockTitleBar(DockPannel *parent);
    ~DockTitleBar() override;

    DockTabBar *tabBar() const;
    QAbstractButton *button(TitleBarButtonRole which) const;

    void updateDockWidgetActionsButtons();

    void setVisible(bool visible) override;

    void insertWidget(int index, QWidget *widget);

    int indexOf(QWidget *widget) const;

    void markTabsMenuOutdated();

signals:
    void tabBarClicked(int index);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void contextMenuEvent(QContextMenuEvent *event) override;

private:
    void onTabsMenuAboutToShow();
    void onCloseButtonClicked();
    void onUndockButtonClicked();
    void onTabsMenuActionTriggered(QAction *action);
    void onCurrentTabChanged(int index);

private:
    DockTitleBarPrivate *d;
    friend class DockTitleBarPrivate;
}; // class DockTitleBar

QADS_END_NAMESPACE
